import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TCP2Thread extends Thread {
	private Socket sock;

	public TCP2Thread(Socket sock) {
		this.sock = sock;
	}

	public void run() {
		try {
			System.out.println(sock.getInetAddress().getHostAddress());
			InputStream is;
			is = sock.getInputStream();
			OutputStream os = sock.getOutputStream();
			int i = is.read();
			while (i != -1) {
				if (i != '\n') {
					System.out.print((char) i);
				} else {
					os.write("Message recieved\n".getBytes());
					os.flush();
				}
				i = is.read();
			}
			sock.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
